/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.giant.bean.parametrics;

import com.giant.entities.InClass;
import com.giant.services.parametrics.ServiceClassLocal;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author taticay
 */
@ManagedBean
@SessionScoped
public class ClassBean implements Serializable{

    
       /**
     * Relación con la interfaz que provee los servicios necesarios del vendedor
     */
    @EJB
    private ServiceClassLocal serviceClass;
    
    private String param="";
    
    private String lineParam="";
    
    private String descParam="";
    
    private String descParam2="";
    
    private List<InClass> allClasses;
    
    private List<InClass> allClassesDesc;
    
      //-----------------------------------------------------------
    // Atributos
    //-----------------------------------------------------------

    /**
     * Representa un nuevo vendedor a ingresar
     */
    private InClass classe = new InClass();
    
    private  String disable = "true";
    private  String disableRide = "true";
     
     //-----------------------------------------------------------
    // Getters y setters
    //-----------------------------------------------------------

   public ClassBean() {
    }
    /**
     * Devuelve el objeto de vendedor actual
     * @return vendedor Vendedor actual
     */
    public InClass getClasse()
    {
        return classe;
    }

    /**
     * Modifica al vendedor actual
     * @param vendedor Nuevo vendedor
     */
    public void setClasse(InClass classe)
    {
        this.classe = classe;
    }

    /**
     * Devuelve todos los vendedores del sistema
     * @return vendedores Lista con todos los vendedores del sistema
     */
    public List<InClass> getClasses()
    {
        
//        System.out.println("clasefiltro");
        if(allClasses==null)
        {
            allClasses=serviceClass.getClasse();
        }
        return allClasses;
    }
    
     public List<InClass> getClassesDesc()
    {
        
//        System.out.println("clasefiltro");
        if(allClassesDesc==null)
        {
            allClassesDesc=serviceClass.getClasse();
        }
        return allClassesDesc;
    }
    
   
    
      public void handleClassChange( String sql, String param) {  
          
          System.out.println("clasesfiltro con parametro "+param+"-> "+this.param);
          if(param.equals("idLine"))
          {
              lineParam=this.param;
          }
          
          if(param.equals("description"))
          {
              descParam=this.param;
          }
          
          if(param.equals("description2"))
          {
              descParam2=this.param;
              return;
          }
          
          Map<String,String> map= new HashMap<String, String>();  
          map.put(param, this.param);
          
         allClasses=this.serviceClass.getClasseFilter(sql, map);
         if(param.equalsIgnoreCase("description")){
              disableRide="false";
              
          }else{
             disable="false";
          for (int i = 0; i < allClasses.size(); i++) {
              String a =allClasses.get(i).getDescription();   
              String b="";
              for (int j = 1; j < allClasses.size(); j++) {
                  b=allClasses.get(j).getDescription();
                  if(a.equalsIgnoreCase(b))     
                     {
                         allClasses.remove(j);
                     }
              }
              
          }
         }
      
         
    } 
      
      
      public void handleClassChangeDes( String sql, String param) {  
          
          System.out.println("clasesfiltro con parametro "+param+"-> "+this.param);
          if(param.equals("idLine"))
          {
              lineParam=this.param;
          }
          
          if(param.equals("description"))
          {
              descParam=this.param;
          }
          
          if(param.equals("description2"))
          {
              descParam2=this.param;
              return;
          }
          
          Map<String,String> map= new HashMap<String, String>();  
          map.put(param, this.param);
          
         allClassesDesc=this.serviceClass.getClasseFilter(sql, map);
      

    } 

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        System.out.println("entro param clase");
//        if(param!=null)
//        {
            this.param = param;
//        }
    }
          public String getDisable() {
        return disable;
    }

    public void setDisable(String disable) {
        this.disable = disable;
    }  
     public String getDisableRide() {
        return disableRide;
    }

    public void setDisableRide(String disableRide) {
        this.disableRide = disableRide;
    }   

    public String getLineParam() {
        return lineParam;
    }

    public void setLineParam(String lineParam) {
        this.lineParam = lineParam;
    }

    public String getDescParam() {
        return descParam;
    }

    public void setDescParam(String descParam) {
        this.descParam = descParam;
    }

    public String getDescParam2() {
        return descParam2;
    }

    public void setDescParam2(String descParam2) {
        this.descParam2 = descParam2;
    }
    
    
    
}
